import { Tooltip, Button, Input, Form, Col, Row, Select, Checkbox } from "antd";
import eventBus, { useSubscribe } from "../../../framework/common/eventBus";

//几个审批类型公用的字段
import getInitFormData from "./getInitFormData"; //获取初始化表单数据
import Opinion from "../components/Opinion"; //审批意见
import SelectAuditors from "../../../RuntimeForm/SelectAuditors/SelectAuditors";
import { NegotiateLogWrap } from "../../../RuntimeForm/ApproveStep/components/NegotiateLogWrap";
import { useEffect } from "react";

//回复协商表单
export default function ({ tplData, urlPrefix, formRef, approveType = "ReplyConsult", approveText }) {
  const [form] = Form.useForm(); //表单对象
  formRef.current = form; //穿透form对象给父组件



  //表单默认值
  if (!tplData.__approveForm__[approveType]) {
    tplData.__approveForm__[approveType] = getInitFormData({
      tplData: tplData,
      fields: {
        opinion: "", //审批意见
      },
    });
  }

  //设置发起表单数据，用于ant表单更新后，反向更新tplData内发起表单的数据
  function updateTplData(data) {
    tplData.__approveForm__[approveType] = {
      ...tplData.__approveForm__[approveType],
      ...data,
    };
  }
  return (
    <>
      <Form
        form={form}
        name="basic"
        labelAlign={"left"}
        colon={false}
        labelCol={{
          flex: "80px",
        }}
        onValuesChange={(value, allValues) => {
          //回填表单数据到tplData
          //比较特殊需要额外回填的，单独到组件内的change事件处理，比如发起组织
          updateTplData(allValues);
        }}
        initialValues={tplData.__approveForm__[approveType]}
        autoComplete="off"
      >
        <Form.Item
          label={approveText + "意见"}
          name="opinion"
          rules={[
            {
                required: true,
                message: '',
            }
        ]}
        >
          <Input.TextArea placeholder={"请输入" + approveText + "意见"} showCount maxLength={1000} style={{ height: 180 }}></Input.TextArea>
        </Form.Item>
      </Form>
    </>
  );
}
